#include<iostream>
#include<sys/socket.h>
#include<unistd.h>
#include<cstring>
#include<sys/types.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<sys/select.h>

#define BACK_LOG 5
namespace so_Sock{
  class so_sock{
      public:
        static int Socket()
        {
          int listen_sock=socket(AF_INET,SOCK_STREAM,0);
          if(listen_sock<0)
          {
            std::cout<<" creat fail sock"<<std::endl;
            exit(1);
          }
          int opt=1;
          setsockopt(listen_sock,SOL_SOCKET,SO_REUSEPORT,&opt,sizeof(opt));
          return listen_sock;
        }

        static bool Bind(int sock,unsigned short port)
        {
          struct sockaddr_in local;
          memset(&local,0,sizeof(0));
          local.sin_family=AF_INET;
          local.sin_port=htons(port);
          local.sin_addr.s_addr=INADDR_ANY;
          int len=sizeof(local);
          if(bind(sock,(struct sockaddr*)&local,len)<0)
          {
            std::cout<<"bind sock fail"<<std::endl;
            exit(2);
          }
          return true;
        }

        static bool Listen(int sock)
        {
          if(listen(sock,BACK_LOG)<0)
          {
            std::cout<<"listen error"<<std::endl;
            exit(3);
          }
          return true;
        }


  };//end class
}//end so_etta
